<template>
	<view>
<!-- 		<view class="searchItem">
			<u-search shape="round" :height="searchObj.height" :input-align="searchObj.inputAlign"
				:show-action="searchObj.showAction" placeholder="名称" @search="onSearch" v-model="searchObj.value">
			</u-search>
		</view>
		<view class="topContainer">
			
		</view> -->
		<template v-for="(item,index) in sandboxList">
			<view class="itemContainer" :key="index">
				<view class="parentWrapper">
					<view class="left" @click="getChildList(item)">
						<view class="title">
							{{item.name}}
						</view>
						<image v-if="item.hasChild" class="icon" :class="{icon_none: !item.isShowMore, icon_more:item.isShowMore}" src="../../static/image/icon_more1.png" mode=""></image>
					</view>
					<view class="right" @click="onShare({
						id: item.shareParam,
						title: item.name,
						sharePath: '/pages/client/web/index?shareParam='+item.shareParam,
						imageUrl: item.shareImage||shopInfo.sandBoxImage||shopInfo.shareImage
					})">
						<image src="../../static/image/icon_share.png" class="icon"></image>
					    分享
					</view> 
<!-- 					<button  style="border: none;padding: 0;margin: 0;" plain="true" type="default"
						@click.stop=""
					    :data-title="item.name"
						:data-id="item.shareParam" 
						:data-imageurl="item.shareImage||shopInfo.sandBoxImage||shopInfo.shareImage"
						:data-sharepath="'/pages/client/web/index?shareParam='+item.shareParam" 
					    open-type="share">
					    <view class="right">
							<image src="../../static/image/icon_share.png" class="icon"></image>
					        分享
					    </view> 
					</button> -->
				</view>	
				<template v-if="item.isShowMore&&item.hasChild">
					<view v-for="(item1,index1) in item.childList" class="childWrapper" :key="index1">
						<view class="left">
							<view class="title">
								{{item1.name}}
							</view>
						</view>
						<view class="right" @click="onShare({
							id: item1.shareParam,
							title: item1.name,
							sharePath: '/pages/client/web/index?shareParam='+item1.shareParam,
							imageUrl: shopInfo.shareImage
						})">
						    分享
						</view> 
						
<!-- 						<button  style="border: none;padding: 0;margin: 0;" plain="true" type="default" 
						    :data-title="item1.name"
							:data-id="item1.shareParam"
              :data-imageurl="shopInfo.shareImage"
							:data-sharepath="'/pages/client/web/index?shareParam='+item1.shareParam" 
						    open-type="share">
						    <view class="right">
						        分享
						    </view> 
						</button> -->
					</view>	
				</template>
																			
			</view>
		</template>
		
	</view>
</template>

<script>
	const api = require("@/static/js/api.js")
	const utils = require("@/static/js/utils.js")
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex';

	let that = null

	export default {
		data() {
			return {
				searchObj: {
					showAction: false,
					inputAlign: "center",
					value: "",
					height: 80,
				},
				sandboxList: [],				
			};
		},

		computed: {
			...mapState({
				hasLogin: state => state.userInfo.hasLogin,
				isAuthPhone: state => state.userInfo.isAuthPhone,
				isAuthUserInfo: state => state.userInfo.isAuthUserInfo,
				isSeller: state => state.userInfo.isSeller,
				sellerObj: state => state.userInfo.sellerObj,
				buyerObj: state => state.userInfo.buyerObj,
				shopInfo: state => state.userInfo.shopInfo,
			}),
		},

		onLoad(options) {
			that = this
			this.parentListMaterial();
		},
		onShow() {

		},
		methods: {
			...mapMutations(['setUserInfo', 'setLoginStatus', 'setUserId', "setOrigin"]),

			//----清空列表


			getChildList(item){
				console.log("childListMaterial", item)
				if (item.hasChild){
					if (item.isShowMore){
						console.log("childListMaterial 0")
						item.isShowMore = false
					}else{
						console.log("childListMaterial 0" ,item.isShowMore)
						if (item.childList.length == 0){
							this.childListMaterial(item);
						}else{
							item.isShowMore = true
						}
					}			
				}			
			},
			
			parentListMaterial() {
				api.listMaterials({			
					param:{
						parentId: "0"
						// limit:5,
						// page: that.cardObj.pageIndex,
						// param: that.searchObj.value
					}				
				}).then(res => {
					that.sandboxList.splice(0, this.sandboxList.length)			
					for (let i = 0; i < res.data.length; i++) {
						res.data[i].childList = [];
						res.data[i].isShowMore = false;
						that.sandboxList.push(res.data[i])
					}
				})
			},
			
			childListMaterial(item) {
				if (item&&item.id&&item.id.length>0){
					
					api.listMaterials({
						param:{
							parentId: item.id
						}				
					}).then(res => {
						item.isShowMore = true;
						item.childList.splice(0, item.childList.length)	
						for (let i = 0; i < res.data.length; i++) {
							item.childList.push(res.data[i])
						}
					})
				}			
			},
		}
	}
</script>
<style>
page{
	background-color: #ffffff;
}
</style>

<style lang="scss">
.searchItem{
	position: fixed;
	top: 0;
	left: 0;
	width: 750rpx;
	background-color: #ffffff;
	padding:  20rpx 30rpx;
}

.topContainer{
	height: 120rpx;
}
.itemContainer{
	width: 750rpx;

	// border-top: 1px solid #ffffff;
	border-bottom: 1px solid #dddddd;
	.parentWrapper{
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #f6f6f6;
		padding: 30rpx 40rpx;
		.left{
			width: 400rpx;
			line-height: 35rpx;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			.title{
				max-width: 300rpx;
				margin-right: 30rpx;
			}
			.icon{
				width: 30rpx;
				height: 30rpx;
				transition-property: all;
				transition-duration: 0.2s;
			}
			.icon_none{
				transform: rotate(-90deg);
			}
			.icon_more{
				transform: rotate(-0deg);
			}
		}
		
		
		.right{
			height: 60rpx;
			width: 140rpx;
			border-radius: 30rpx;
			background-color: #007aff;
			color: #ffffff;
			font-size: 22rpx;
			text-align: center;
			line-height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			.icon{
				width: 30rpx;
				height: 30rpx;
				margin-right: 10rpx;
			}
		}
		
	}
	.childWrapper{
		width: 690rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ffffff;
		padding: 15rpx 40rpx 15rpx 0;
		margin-left: 60rpx;
		border-top: 1px solid #dddddd;
		.left{
			width: 400rpx;
			line-height: 35rpx;
			font-size: 26rpx;
			display: flex;
			align-items: center;
			.title{
				max-width: 350rpx;
			}
			.icon{
				width: 20rpx;
				height: 20rpx;
			}
		}
		
		
		.right{
			height: 55rpx;
			width: 100rpx;
			border-radius: 27rpx;
			background-color: #007aff;
			color: #ffffff;
			font-size: 22rpx;
			text-align: center;
			line-height: 55rpx;
		}
		
	}
}

</style>
